#include <ctime>
#include <iostream>
#include <fstream>

using namespace std;

void lis(int masA[], int masL) {
	while(masL--) 	{
		bool cat = false;
		
		for(int i = 0; i < masL; i++) {
			if(masA[i] > masA[i + 1]){
				swap(masA[i], masA[i + 1]);
				cat = true;
			}
		}	
	
		if(cat == false) break;
	}
}

void read_from_file(const char *filename, int a[], int length) {
    ifstream file(filename);

    for(int i=0; i < length; i++)
        file >> a[i];
}

int main()
{
    #define LEN 5000
    int a[LEN];

    read_from_file("m1_sorted.txt",a,LEN);
    unsigned int t1 =  clock(); 
    lis(a,LEN);
    unsigned int t2 = clock(); 
    unsigned int t_work = t2 - t1; 
    cout<<"m1_sorted " << t_work << " milliseconds \n";
    
    read_from_file("m2_reverse.txt",a,LEN);
    t1 =  clock(); 
    lis(a,LEN);
    t2 = clock(); 
    t_work = t2 - t1; 
    cout<<"m2_reverse " << t_work << " milliseconds \n";
    
    read_from_file("m3_shuffle.txt",a,LEN);
    t1 =  clock(); 
    lis(a,LEN);
    t2 = clock(); 
    t_work = t2 - t1; 
    cout<<"m3_shuffle " << t_work << " milliseconds \n";
    
    return 0;
}
